using Abp.Application.Services;
using Abp.Application.Services.Dto;
using Abp.Domain.Repositories;
using Abp.Linq.Extensions;
using HCD.Const;
using HCD.Dict.Dtos;
using HCD.Entities;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using System.Threading.Tasks;

namespace HCD.Mdt
{
    [Route("api/[controller]/[action]"),ApiController]
    public class SimpleDictAppService : AsyncCrudAppService<SimpleDict,SimpleDictDto,long, SimpleDictGetAllInput, SimpleDictAddInput, SimpleDictEditInput, EntityDto<long>, EntityDto<long>>, ISimpleDictAppService
    {
        public SimpleDictAppService(IRepository<SimpleDict,long> repository)
        : base(repository)
        {
            LocalizationSourceName = EnterpriseConsts.LocalizationSourceName;
        }
        /// <summary>
        /// 新增单个配置
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost,ActionName("Add")]
        public override async Task<SimpleDictDto> CreateAsync(SimpleDictAddInput input)
        {
            return await base.CreateAsync(input);
        }
        /// <summary>
        /// 编辑单个配置
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut, ActionName("Edit")]
        public override async Task<SimpleDictDto> UpdateAsync(SimpleDictEditInput input)
        {
            return await base.UpdateAsync(input);
        }
        /// <summary>
        /// 删除单个配置
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpDelete, ActionName("Delete")]
        public override async Task DeleteAsync(EntityDto<long> input)
        {
            await base.DeleteAsync(input);
        }
        /// <summary>
        /// 获取单个配置
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet, ActionName("Get")]
        public override async Task<SimpleDictDto> GetAsync([FromQuery]EntityDto<long> input)
        {
            return await base.GetAsync(input);
        }

        /// <summary>
        /// 获取SimpleDict数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns>根据分页参数返回分页数据</returns>
        [HttpGet, ActionName("GetList")]
        public override async Task<PagedResultDto<SimpleDictDto>> GetAllAsync([FromQuery]SimpleDictGetAllInput input)
        {
            return await base.GetAllAsync(input);
        }
        protected override IQueryable<SimpleDict> CreateFilteredQuery(SimpleDictGetAllInput input)
        {
            return base.CreateFilteredQuery(input)
                .WhereIf(!string.IsNullOrWhiteSpace(input.Query), t => t.TypeName.Contains(input.Query))
                .WhereIf(!string.IsNullOrWhiteSpace(input.TypeCode), t => t.TypeCode == input.TypeCode);
        }
    }
}


